﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using System;
using NJamb.NUnit;
using NJamb.Parser.SpecificationBuilders.SubjectIs.Extensions;
using NJamb.Parser.SubjectBuilders;
using NJamb.Specifications.Simple.Singular;
using NUnit.Framework;
using Stile.Patterns.SelfDescribingPredicates;
#endregion

namespace NJamb.Tests.Parser.SpecificationBuilders.SubjectIs
{
    [TestFixture]
    public class IsStringExtensionsFixture : EvaluatingSampleFixture
    {
        [Test]
        public void StringContaining()
        {
            const string part = "the";
            _sample.String = "hi there";
            Assert.That(_sample.String.Contains(part), Is.True);

            // arrange
            ISingularSpecification<string> specification =
                Specify.For(() => _sample).That(x => x.String).Is.Not.StringContaining(part);

            // act
            IEvaluation<string> evaluation = specification.Evaluate();

            // assert
            AssertEvaluationFailed(evaluation,
                "expected _sample.String would not contain \"the\"" + Environment.NewLine + " but was \"hi there\".");
        }

        [Test]
        public void StringEndingWith()
        {
            const string end = "there";
            _sample.String = "hi there";
            Assert.That(_sample.String.Contains(end), Is.True);

            // arrange
            ISingularSpecification<string> specification =
                Specify.For(() => _sample).That(x => x.String).Is.Not.StringEndingWith(end);

            // act
            IEvaluation<string> evaluation = specification.Evaluate();

            // assert
            AssertEvaluationFailed(evaluation,
                "expected _sample.String would not end with \"there\"" + Environment.NewLine + " but was \"hi there\".");
        }

        [Test]
        public void StringStartingWith()
        {
            const string start = "hi";
            _sample.String = "hi there";
            Assert.That(_sample.String.StartsWith(start), Is.True);

            // arrange
            ISingularSpecification<string> specification =
                Specify.For(() => _sample).That(x => x.String).Is.Not.StringStartingWith(start);

            // act
            IEvaluation<string> evaluation = specification.Evaluate();

            // assert
            AssertEvaluationFailed(evaluation,
                "expected _sample.String would not start with \"hi\"" + Environment.NewLine + " but was \"hi there\".");
        }
    }
}
